package com.example.se2_funmessages;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

public class ViewSavedMessage extends Activity {

	private static final String EXTRA_MESSAGE = null;
	
	String toStr, fromStr, bodyStr;
	int messageId;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_view_saved_message);
		
		// Get Intent from main activity
		Intent in = getIntent();
		String[] contents = in.getStringArrayExtra(EXTRA_MESSAGE);
		// Get Intents arguments that pass the message contents, to and from
		TextView to = (TextView)findViewById(R.id.toFieldFill);
		TextView from = (TextView)findViewById(R.id.fromFieldFill);
		TextView body = (TextView)findViewById(R.id.messageFill);
		TextView date = (TextView)findViewById(R.id.datefill2);
		// Set the fields with content
		toStr = contents[4];
		fromStr = contents[5];
		bodyStr = contents[2];
		messageId = Integer.parseInt(contents[3]);
		to.setText(contents[0]);
		from.setText(contents[1]);
		body.setText(contents[2]);
		date.setText("Received: " + contents[6]);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_view_message, menu);
		return true;
	}
	
	public void back(View view)
	{
		this.finish();
	}
	
	public void delete(View view)
	{
		DatabaseHandler dbh = new DatabaseHandler(this);
		dbh.deleteMessageFromSavedDatabase(messageId,toStr,fromStr);
		dbh.close();
		Toast.makeText(getApplicationContext(), "Success! Message Deleted", Toast.LENGTH_SHORT).show();
		this.finish();
	}
	


}
